package com.ruoyi.group.service.impl;

import java.util.Date;
import java.util.List;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.system.mapper.SysUserMapper;
import com.ruoyi.system.service.ISysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.group.mapper.CustomerMapper;
import com.ruoyi.group.domain.Customer;
import com.ruoyi.group.service.ICustomerService;

import javax.annotation.Resource;

/**
 * 客户基本信息Service业务层处理
 *
 * @author ruoyi
 * @date 2022-11-27
 */
@Service
public class CustomerServiceImpl extends ServiceImpl<CustomerMapper, Customer> implements ICustomerService {

    /**
     * 查询客户基本信息列表
     *
     * @param customer 客户基本信息
     * @return 客户基本信息
     */
    @Override
    public List<Customer> selectCustomerList(Customer customer) {
        return getBaseMapper().selectCustomerList(customer);
    }

    @Override
    public int saveCustomer(Customer customer) {
        List<Customer> customers = getBaseMapper().selectList(
                new LambdaQueryWrapper<Customer>().eq(Customer::getEnterpriseName,customer.getEnterpriseName()));
            if (customers.size()!=0){
                throw new ServiceException("企业名称不能重复");
        }
        customer.setInputUser(SecurityUtils.getUserId());
        customer.setInputTime(new Date());
        return getBaseMapper().insert(customer);
    }
}
